<template>
  <div>
    <el-table
      :data="bannerList"
      style="width: 100%; margin-bottom: 20px"
      row-key="id"
      border
      :tree-props="{ children: 'children', hasChildren: 'hasChildren' }"
    >
      <el-table-column prop="id" label="编号"> </el-table-column>
      <el-table-column prop="title" label="轮播图标题"> </el-table-column>
      <el-table-column label="图片">
        <template slot-scope="scoped">
          <div class="img">
            <img :src="$pre + scoped.row.img" alt="" />
          </div>
        </template>
      </el-table-column>
      <el-table-column label="状态">
        <template slot-scope="scoped">
          <div>
            <el-button type="success" v-if="scoped.row.status == 1"
              >启 用</el-button
            >
            <el-button type="info" v-else>禁 用</el-button>
          </div>
        </template>
      </el-table-column>
      <el-table-column label="操作">
        <template slot-scope="scoped">
          <div>
            <el-button @click="edit(scoped.row.id)">编 辑</el-button>
            <el-button @click="del(scoped.row.id)">删 除</el-button>
          </div>
        </template>
      </el-table-column>
    </el-table>
  </div>
</template>

<script>
import { mapActions, mapGetters } from "vuex";
import { bannerDelete } from "../../../request/api";
import { successAlert, warningAlert } from "../../../utils/alert";
export default {
  methods: {
    ...mapActions({
      asyncBannerList: "banner/asyncChangeList",
    }),
    del(id) {
      bannerDelete({ id: id }).then((res) => {
        if (res.data.code == 200) {
          successAlert(res.data.msg);
          //重新请求列表数据
          this.asyncBannerList()
        } else {
          warningAlert(res.data.msg);
        }
      });
    },
    edit(id) {
      this.$emit("edit", id);
    },
  },
  computed: {
    ...mapGetters({
      bannerList: "banner/list",
    }),
  },
  mounted() {
    this.asyncBannerList()
  },
};
</script>

<style scoped>
.img img {
  width: 150px;
}
</style>